package com.hkts.management.returnfee.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.management.common.utils.Result;
import com.hkts.management.common.utils.ResultUtil;
import com.hkts.management.returnfee.entity.HktsReturnFail;
import com.hkts.management.returnfee.service.IHktsReturnFailService;
import com.hkts.management.utils.CustomPageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author hml
 * @since 2021-05-21
 */
@RestController
@RequestMapping("/order/hktsReturnFail")
@Api(tags = "退费api")
public class HktsReturnFailController {
    private final Logger logger = LoggerFactory.getLogger(HktsReturnFailController.class);

    @Autowired
    public IHktsReturnFailService iHktsReturnFailService;

    /**
     * 分页查询数据
     *
     * @param page           分页信息
     * @param hktsReturnFail 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getHktsReturnFailPageList")
    public Result<Object> getHontUserList(Page<HktsReturnFail> page, HktsReturnFail hktsReturnFail) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iHktsReturnFailService.selectPage(page, hktsReturnFail)));
    }

    /**
     * 保存和修改公用的
     *
     * @param hktsReturnFail 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsReturnFailSave")
    public Result<Object> hktsReturnFailSave(HktsReturnFail hktsReturnFail) {
        iHktsReturnFailService.saveOrUpdate(hktsReturnFail);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/hktsReturnFailGetById")
    public Result<Object> hktsReturnFailGetById(String id) {
        HktsReturnFail byId = iHktsReturnFailService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsReturnFailDelete")
    public Result<Object> hontUserDelete(String id) {
        iHktsReturnFailService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsReturnFailBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iHktsReturnFailService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }

    /*
     * 退款回调
     * */
    @ResponseBody
    @RequestMapping("/refundNoticeUrl")
    @ApiOperation(value = "退费回调，微信使用")
    public String refundNoticeUrl(HttpServletRequest request) {
        try {
            return iHktsReturnFailService.refundNoticeUrl(request);
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }
}
